# -*- coding: utf-8 -*-
import os
import sys
import getopt
import traceback


def transform(src,dst):
    data = ""
    with open(src,"r") as data_file:
        data += data_file.read().replace("\n","")

    splits = data.split(";")
    
    filter_data = ""
    data_set = {}
    for text in splits:
        _text = text.strip()
        # start = _text.index("|") + 1
        # _text= _text[start:]
        if not _text in data_set:
            data_set[_text] = True
            filter_data += _text
            filter_data += "\n"

    with open(dst,"w") as data_file:
        data_file.write(filter_data)

    print("complete")

def main() -> int:
    input_file = ""
    output_file = ""

    try:
        opts,args = getopt.getopt(sys.argv[1:],"i:o:")
    except getopt.GetoptError:
        print(f"{sys.argv[0]} -i <inputfile> -o <outputfile>")

    for opt, arg in opts:
        if opt == "-i":
            input_file = arg
        elif opt == "-o":
            output_file  = arg
    
    print(f"input: {input_file}")
    print(f"output: {output_file}")

    transform(input_file,output_file)

    return 0



# -------------- main --------------
if __name__ == '__main__':
    sys_ret = 0
    try:
        sys_ret = main()
    except Exception as e:
        print(e)
        traceback.print_exc()
        sys_ret = 1
    finally:
        sys.exit(sys_ret)